<template>
  <a-card :bordered="false">
    <a-table
      :columns="columns"
      :dataSource="dataList"
      :loading="loading"
      :pagination="pagination"
      :rowKey="record => record.id"
      :scroll="{ x: 3000 }"
      @change="handleTableChange"
      bordered
    >
    </a-table>
  </a-card>
</template>

<script>
import { delObj, fetchList } from '@api/sys/log'

const statusList = [
  {
    label: '正常',
    value: '0'
  },
  {
    label: '异常',
    value: '1'
  }
]
export default {
  name: 'User',
  data () {
    return {
      statusList,
      loading: false,
      columns: [
        {
          title: '序号',
          width: '100px',
          fixed: 'left',
          customRender: (text, record, index) => (index + 1)
        },
        {
          title: '日志类型',
          fixed: 'left',
          width: '100px',
          dataIndex: 'logType',
          customRender: (text, record, index) => {
            return (
              <div>
                {
                  statusList.find(item => item.value === text).label
                }
              </div>
            )
          }
        },
        {
          title: '用户名',
          width: '100',
          dataIndex: 'username'
        }, {
          title: '用户操作',
          width: '150px',
          dataIndex: 'operation'
        },
        {
          title: '请求方法',
          dataIndex: 'method'
        },
        {
          title: '请求参数',
          dataIndex: 'params'
        },
        {
          title: '执行时长(毫秒)',
          dataIndex: 'time'
        },
        {
          title: '模块名称',
          width: '10%',
          dataIndex: 'moduleName'
        },
        {
          title: '来源ip',
          width: '10%',
          dataIndex: 'ip'
        },
        {
          title: '创建时间',
          width: '10%',
          dataIndex: 'createTime'
        }, {
          title: '请求方法',
          width: '10%',
          dataIndex: 'requestMethod'
        },
        {
          title: '异常',
          width: '10%',
          dataIndex: 'exception'
        },
        {
          title: '操作',
          width: '160px',
          fixed: 'right',
          customRender: (text, record, index) => {
            return (
              <div>
                <a href="javascript:" onClick={() => {
                }}>查看</a>
                <a-divider type="vertical"/>
                <a-dropdown>
                  <a className="ant-dropdown-link">更多
                    <a-icon type="down"/>
                  </a>
                  <a-menu slot="overlay">
                    <a-menu-item>
                      <a onClick={() => {
                      }}>编辑</a>
                    </a-menu-item>
                    <a-menu-item>
                      <a-popconfirm title="是否删除信息" onConfirm={() => {
                      }} okText="是" cancelText="否">
                        <a-icon slot="icon" type="question-circle-o" style="color: red"/>
                        <a href="javascript:" style="color: red">删除</a>
                      </a-popconfirm>
                    </a-menu-item>
                    <a-menu-item>
                      <a onClick={() => {
                      }}>盘点</a>
                    </a-menu-item>
                  </a-menu>
                </a-dropdown>
              </div>
            )
          }
        }
      ],
      queryParam: {
        moduleName: '',
        logType: '',
        pageSize: '',
        current: ''
      },
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showSizeChanger: true
      },
      dataList: []
    }
  },
  mounted () {
    this.init()
  },
  methods: {
    init () {
      this.loading = true
      this.queryParam.pageSize = this.pagination.pageSize
      this.queryParam.current = this.pagination.current
      fetchList(this.queryParam).then(res => {
        this.dataList = res.data.content
        this.pagination.total = Number(res.data.totalElements)
      }).finally(_ => {
        this.loading = false
      })
    },
    handleTableChange (pagination, filters, sorter) {
      const pager = { ...this.pagination }
      pager.current = pagination.current
      pager.pageSize = pagination.pageSize
      this.pagination = pager
      this.init()
    },
    delete (record) {
      delObj(record.id).then(res => {
        this.$message.info('删除成功')
        this.queryPage()
      })
    },
    handleOk () {
      this.queryPage()
    }
  }
}
</script>

<style scoped>

</style>
